<?php
namespace PsiFramework\Classes\Util\UI;

/**
 * PsiFramework
 * Php Simple Framework
 *
 * @author Rémi San
 * @version beta
 */


/**
 * The Printer is used to print data to the screen
 *
 * @package Util.UI
 */
class Printer
{

    /**
     * Prints the string through htmlentities and nl2br
     *
     * @param       string  $string the string to display
     */
    public static function display(/*string*/ $string)
    {
        echo self::getText($string);
    }

    /**
     * Returns the string through htmlentities
     *
     * @param       string  $string the string to display
     */
    public static function getText(/*string*/ $string, /*boolean*/ $nl2br=true)
    {
        $htmlText = htmlentities($string, ENT_QUOTES, "UTF-8");
        if ($nl2br) {
            $htmlText = nl2br($htmlText);
        }
        return $htmlText;
    }

    /**
     * Prints the string encoded for url
     *
     * @param       string  $url    the string to display
     */
    public static function url(/*string*/ $url)
    {
        echo self::getUrl($url);
    }

    /**
     * Returns the string encoded for url
     *
     * @param       string  $url    the string to display
     * @return    string
     */
    public static function getUrl(/*string*/ $url)
    {
        return urlencode($url);
    }

    /**
     * Prints the string with \n turned to <br />
     *
     * @param       string  $url    the string to show
     */
    public static function show(/*string*/ $string)
    {
        echo nl2br($string);
    }
}
